home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DEV / I-Z / TE32K.sit / TE32K Demo Folder / TE32K Source ƒ / windows.c < prev   
C/C++ Source or Header  |  1993-01-01  |  18KB  |  921 lines

  1. #include "TE32K.h"
  2. #include <stdio.h>
  3.  
  4.  
  5. #define    INDENT    5
  6.  
  7. extern    WindowPtr        theWPtr;
  8. extern    TE32KHandle        theTEH32K;
  9. extern    ControlHandle    theVScroll,theHScroll;
  10. extern    Cursor            editCursor,waitCursor;
  11. extern    char            changed;
  12. extern    SFReply            mySFReply;
  13. extern    int                defaultFont,defaultFontSize;
  14.  
  15.  
  16. SetUpCursors()
  17. {
  18. CursHandle    hCurs;
  19.     
  20.     hCurs = GetCursor(iBeamCursor);
  21.     editCursor = **hCurs;
  22.     
  23.     hCurs = GetCursor(watchCursor);
  24.     waitCursor = **hCurs;
  25. }
  26.  
  27.  
  28.  
  29. DoMouseDown(theEvent)
  30. EventRecord    *theEvent;
  31. {
  32. WindowPtr    whichWindow;
  33. int            windowCode;
  34.  
  35.     windowCode = FindWindow(theEvent->where,&whichWindow);
  36.     
  37.     switch (windowCode = FindWindow(theEvent->where,&whichWindow)) 
  38.     {
  39.         case inMenuBar:
  40.             DoCommand(MenuSelect(theEvent->where));
  41.             break;
  42.             
  43.         case inSysWindow:
  44.             SystemClick(theEvent,whichWindow);
  45.             break;
  46.             
  47.         case inContent:
  48.             if (whichWindow != FrontWindow())
  49.                 SelectWindow(whichWindow);
  50.             
  51.             else if (IsOurWindow(whichWindow))
  52.                 DoContent(whichWindow,theEvent);
  53.             
  54.             break;
  55.         
  56.         case inDrag:
  57.             if (whichWindow != FrontWindow())
  58.                 SelectWindow(whichWindow);
  59.             
  60.             else if (IsOurWindow(whichWindow))
  61.                 DoDrag(whichWindow,theEvent);
  62.             
  63.             break;
  64.             
  65.         case inGrow:
  66.             if (whichWindow != FrontWindow())
  67.                 SelectWindow(whichWindow);
  68.             
  69.             else if (IsOurWindow(whichWindow))
  70.                 DoGrow(whichWindow,theEvent);
  71.             
  72.             break;
  73.         
  74.         case inZoomIn:
  75.         case inZoomOut:
  76.             if (whichWindow != FrontWindow())
  77.                 SelectWindow(whichWindow);
  78.             
  79.             else if (IsOurWindow(whichWindow) && TrackBox(whichWindow,theEvent->where,windowCode))
  80.                 DoZoom(whichWindow,windowCode);
  81.             
  82.             break;
  83.         
  84.         case inGoAway:
  85.             if (whichWindow != FrontWindow())
  86.                 SelectWindow(whichWindow);
  87.             
  88.             else if (IsOurWindow(whichWindow) && TrackGoAway(whichWindow,theEvent->where))
  89.                 DoCloseWindow(whichWindow);
  90.             
  91.             break;
  92.     }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. IsOurWindow(whichWindow)
  101. WindowPtr    whichWindow;
  102. {
  103.     if (theWPtr && whichWindow == theWPtr)
  104.         return(TRUE);
  105.     else
  106.         return(FALSE);
  107. }
  108.  
  109.  
  110.  
  111. DoActivateDeactivate(whichWindow,adFlag)
  112. WindowPtr    whichWindow;char    adFlag;
  113. {
  114. Rect            tempRect;
  115. GrafPtr            oldPort;
  116.  
  117.     if (whichWindow == theWPtr)
  118.     {
  119.         GetPort(&oldPort);
  120.         SetPort(whichWindow);
  121.         
  122.         if (adFlag)
  123.         {
  124.             HiliteControl(theVScroll,0);
  125.             HiliteControl(theHScroll,0);
  126.             TE32KActivate(theTEH32K);
  127.         }
  128.         else
  129.         {
  130.             HiliteControl(theVScroll,255);
  131.             HiliteControl(theHScroll,255);
  132.             TE32KDeactivate(theTEH32K);
  133.         }
  134.         
  135.         DrawGrowIcon(whichWindow);
  136.         
  137.         SetPort(oldPort);
  138.         
  139.         return(TRUE);
  140.     }
  141.     
  142.     else
  143.         return(FALSE);
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. DoCloseWindow(whichWindow)
  152. WindowPtr    whichWindow;
  153. {
  154. int        userChoice;
  155.  
  156.     if (theWPtr && whichWindow==theWPtr)
  157.     {
  158.         if (changed)
  159.         {
  160.             userChoice = YesNoCancel("Save changes?",3);
  161.             
  162.             if (userChoice == 3)
  163.                 return(FALSE);
  164.             
  165.             else if (userChoice == 1 && !SaveTextFile(theTEH32K,&mySFReply))
  166.                 return(FALSE);
  167.         }        
  168.         
  169.         if (theVScroll) DisposeControl(theVScroll);
  170.         if (theHScroll) DisposeControl(theHScroll);
  171.         if (theTEH32K) TE32KDispose(theTEH32K);
  172.         if (theWPtr) DisposeWindow(theWPtr);
  173.         
  174.         theWPtr = 0L;
  175.         theTEH32K = 0L;
  176.         theVScroll = 0L;
  177.         theHScroll = 0L;
  178.         
  179.         return(TRUE);
  180.     }
  181.     
  182.     else
  183.         return(FALSE);
  184. }
  185.  
  186.  
  187.  
  188. DoGrow(whichWindow,theEvent)
  189. WindowPtr    whichWindow;EventRecord    *theEvent;
  190. {
  191. Rect            tempRect;
  192. long            newSize;
  193. GrafPtr            oldPort;
  194.  
  195.     if (theWPtr && whichWindow==theWPtr)
  196.     {
  197.         SetRect(&tempRect,100,50,32767,32767);
  198.         newSize = GrowWindow(whichWindow,theEvent->where,&tempRect);
  199.         SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),0xff);
  200.         tempRect = whichWindow->portRect;
  201.         GetPort(&oldPort);
  202.         SetPort(whichWindow);
  203.         EraseRect(&tempRect);
  204.         InvalRect(&tempRect);
  205.         
  206.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  207.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  208.         
  209.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  210.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  211.         
  212.         AdjustForResizedWindow();
  213.         
  214.         SetPort(oldPort);
  215.         
  216.         return(TRUE);
  217.     }
  218.     
  219.     else
  220.         return(FALSE);
  221. }
  222.  
  223.  
  224.  
  225.  
  226. DoZoom(whichWindow,windowCode)
  227. WindowPtr    whichWindow;int windowCode;
  228. {
  229. Rect            tempRect;
  230. GrafPtr            oldPort;
  231.  
  232.     if (theWPtr && whichWindow==theWPtr)
  233.     {
  234.         GetPort(&oldPort);
  235.         SetPort(whichWindow);
  236.         
  237.         tempRect = whichWindow->portRect;
  238.         EraseRect(&tempRect);
  239.         
  240.         ZoomWindow(whichWindow, windowCode, 0);
  241.         
  242.         tempRect = whichWindow->portRect;
  243.         EraseRect(&tempRect);
  244.         
  245.         MoveControl(theVScroll,tempRect.right+1-16,tempRect.top-1);
  246.         SizeControl(theVScroll,16,whichWindow->portRect.bottom-14-(whichWindow->portRect.top-1));
  247.         
  248.         MoveControl(theHScroll,tempRect.left-1,tempRect.bottom+1-16);
  249.         SizeControl(theHScroll,whichWindow->portRect.right-14-(whichWindow->portRect.left-1),16);
  250.         
  251.         AdjustForResizedWindow();
  252.         
  253.         tempRect = whichWindow->portRect;
  254.         InvalRect(&tempRect);
  255.         
  256.         SetPort(oldPort);
  257.         
  258.         return(TRUE);
  259.     }
  260.     
  261.     else
  262.         return(FALSE);
  263. }
  264.  
  265.  
  266.  
  267. DoDrag(whichWindow,theEvent)
  268. WindowPtr    whichWindow;EventRecord    *theEvent;
  269. {
  270. Rect            tempRect;
  271.  
  272.     if (theWPtr && whichWindow == theWPtr)
  273.     {
  274.         SetRect(&tempRect,screenBits.bounds.left+10,screenBits.bounds.top+25,screenBits.bounds.right-10,screenBits.bounds.bottom-25);
  275.         DragWindow(whichWindow,theEvent->where,&tempRect);
  276.         return(TRUE);
  277.     }
  278.     
  279.     else
  280.         return(FALSE);
  281. }
  282.  
  283.  
  284.  
  285.  
  286. AdjustScrollBar()
  287. {
  288. int        ctlVal,screenLines,numLines;
  289.  
  290.     ctlVal = ((*theTEH32K)->viewRect.top - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight;
  291.     screenLines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  292.     numLines = (**theTEH32K).nLines;
  293.     
  294.     if (ctlVal > numLines-screenLines)
  295.         SetCtlMax(theVScroll,ctlVal);
  296.     else
  297.         SetCtlMax(theVScroll,(numLines-screenLines > 0) ? numLines-screenLines : 0);
  298.     
  299.     SetCtlValue(theVScroll,ctlVal);
  300. }
  301.  
  302.  
  303.  
  304. AdjustForResizedWindow()
  305. {
  306. LongRect    tempLongRect;
  307. Rect        tempRect;
  308.  
  309.     SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  310.     tempRect.bottom = tempRect.top + ((tempRect.bottom - tempRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  311.     
  312.     RectToLongRect(&tempRect,&((*theTEH32K)->viewRect));
  313.     
  314.     RectToLongRect(&tempRect,&((*theTEH32K)->destRect));
  315.     (*theTEH32K)->destRect.top -= (long) GetCtlValue(theVScroll)*(*theTEH32K)->lineHeight;
  316.     (*theTEH32K)->destRect.left -= (long) GetCtlValue(theHScroll)*(*theTEH32K)->lineHeight;
  317.     
  318.     (**theTEH32K).destRect.right -= 10;
  319.     
  320.     TE32KFromScrap();
  321.     
  322.     SetCursor(&waitCursor);
  323.     TE32KCalText(theTEH32K);
  324.     InitCursor();
  325.     
  326.     AdjustScrollBar();
  327. }
  328.  
  329.  
  330.  
  331. pascal void myScrollProc(theControl, theCode)
  332. ControlHandle    theControl;int    theCode;
  333. {
  334. long        scrollAmt,lines,numLines;
  335. int            controlMax,controlMin,controlVal;
  336. RgnHandle    updateRgn;
  337.     
  338.     if (theVScroll && theControl==theVScroll)
  339.     {
  340.         controlMax = GetCtlMax(theControl);
  341.         controlMin = GetCtlMin(theControl);
  342.         controlVal = GetCtlValue(theControl);
  343.         
  344.         updateRgn = NewRgn();
  345.         
  346.         switch (theCode) 
  347.         {
  348.             case inUpButton:
  349.                 if (controlVal > controlMin)
  350.                 {
  351.                     SetCtlValue(theControl,controlVal-1);
  352.                     
  353.                     TE32KScroll(0L,(long) (**theTEH32K).lineHeight,theTEH32K);
  354.                 }
  355.                 
  356.                 break;
  357.                 
  358.             case inDownButton: 
  359.                 if (controlVal < controlMax)
  360.                 {
  361.                     SetCtlValue(theControl,controlVal+1);
  362.                     
  363.                     TE32KScroll(0L,(long) -(**theTEH32K).lineHeight,theTEH32K);
  364.                 }
  365.                 
  366.                 break;
  367.     
  368.             case inPageUp: 
  369.                 if (controlVal > controlMin)
  370.                 {
  371.                     lines = ((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(**theTEH32K).lineHeight;
  372.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  373.                     SetCtlValue(theControl,controlVal-scrollAmt);
  374.                     TE32KScroll(0L,(long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  375.                 }
  376.                 
  377.                 break;
  378.     
  379.             case inPageDown: 
  380.                 if (controlVal < controlMax)
  381.                 {
  382.                     lines = ((**theTEH32K).viewRect.bottom - (**theTEH32K).viewRect.top)/(**theTEH32K).lineHeight;
  383.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  384.                     SetCtlValue(theControl,controlVal+scrollAmt);
  385.                     TE32KScroll(0L,(long) ((long) -scrollAmt * (long) (**theTEH32K).lineHeight),theTEH32K);
  386.                 }
  387.                 
  388.                 break;
  389.         }
  390.         
  391.         AdjustScrollBar();
  392.         
  393.         DisposeRgn(updateRgn);
  394.     }
  395.     
  396.     else if (theHScroll && theControl==theHScroll)
  397.     {
  398.         controlMax = GetCtlMax(theControl);
  399.         controlMin = GetCtlMin(theControl);
  400.         controlVal = GetCtlValue(theControl);
  401.         
  402.         updateRgn = NewRgn();
  403.         
  404.         switch (theCode) 
  405.         {
  406.             case inUpButton:
  407.                 if (controlVal > controlMin)
  408.                 {
  409.                     SetCtlValue(theControl,controlVal-1);
  410.                     
  411.                     TE32KScroll((long) (**theTEH32K).lineHeight,0L,theTEH32K);
  412.                 }
  413.                 
  414.                 break;
  415.                 
  416.             case inDownButton: 
  417.                 if (controlVal < controlMax)
  418.                 {
  419.                     SetCtlValue(theControl,controlVal+1);
  420.                     
  421.                     TE32KScroll((long) -(**theTEH32K).lineHeight,0L,theTEH32K);
  422.                 }
  423.                 
  424.                 break;
  425.     
  426.             case inPageUp: 
  427.                 if (controlVal > controlMin)
  428.                 {
  429.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  430.                     scrollAmt = (controlVal-lines < controlMin) ? controlVal-controlMin : lines;
  431.                     SetCtlValue(theControl,controlVal-scrollAmt);
  432.                     TE32KScroll((long) ((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  433.                 }
  434.                 
  435.                 break;
  436.     
  437.             case inPageDown: 
  438.                 if (controlVal < controlMax)
  439.                 {
  440.                     lines = ((*theTEH32K)->viewRect.right - (*theTEH32K)->viewRect.left)/(2 * (**theTEH32K).lineHeight);
  441.                     scrollAmt = (controlVal+lines > controlMax) ? controlMax-controlVal : lines;
  442.                     SetCtlValue(theControl,controlVal+scrollAmt);
  443.                     TE32KScroll((long) -((long) scrollAmt * (long) (**theTEH32K).lineHeight),0L,theTEH32K);
  444.                 }
  445.                 
  446.                 break;
  447.         }
  448.         
  449.         AdjustScrollBar();
  450.         
  451.         DisposeRgn(updateRgn);
  452.     }
  453. }
  454.  
  455.  
  456.  
  457.  
  458.  
  459. DoContent(whichWindow,theEvent)
  460. WindowPtr    whichWindow;EventRecord    *theEvent;
  461. {
  462. GrafPtr            oldPort;
  463. ControlHandle    whichControl;
  464. int                cntlCode,ctlVal,oldVal;
  465. Rect            tempRect;
  466.  
  467.     if (theWPtr && whichWindow==theWPtr)
  468.     {
  469.         GetPort(&oldPort);
  470.         SetPort(whichWindow);
  471.         
  472.         LongRectToRect(&((**theTEH32K).viewRect),&tempRect);
  473.         
  474.         GlobalToLocal(&(theEvent->where));
  475.         
  476.         cntlCode = FindControl(theEvent->where,whichWindow,&whichControl);
  477.         
  478.         if (theVScroll && whichControl == theVScroll && cntlCode != 0)
  479.         {
  480.             if (cntlCode == inThumb)
  481.             {
  482.                 oldVal = GetCtlValue(whichControl);
  483.                 
  484.                 TrackControl(whichControl,theEvent->where,0L);
  485.                 
  486.                 TE32KScroll(0L,(long) ((oldVal - GetCtlValue(whichControl)) * (**theTEH32K).lineHeight),theTEH32K);
  487.             }
  488.             
  489.             else
  490.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  491.         }
  492.         
  493.         else if (theHScroll && whichControl == theHScroll && cntlCode != 0)
  494.         {
  495.             if (cntlCode == inThumb)
  496.             {
  497.                 oldVal = GetCtlValue(whichControl);
  498.                 
  499.                 TrackControl(whichControl,theEvent->where,0L);
  500.                 
  501.                 TE32KScroll((long) ((oldVal - GetCtlValue(whichControl)) * (**theTEH32K).lineHeight),0L,theTEH32K);
  502.             }
  503.             
  504.             else
  505.                 TrackControl(whichControl,theEvent->where,myScrollProc);
  506.         }
  507.         
  508.         else if (PtInRect(theEvent->where,&tempRect))
  509.         {
  510.             if (theEvent->modifiers & shiftKey)
  511.                 TE32KClick(theEvent->where,TRUE,theTEH32K);
  512.             else
  513.                 TE32KClick(theEvent->where,FALSE,theTEH32K);
  514.         }
  515.         
  516.         SetPort(oldPort);
  517.         
  518.         return(TRUE);
  519.     }
  520.     
  521.     else
  522.         return(FALSE);
  523. }
  524.  
  525.  
  526.  
  527.  
  528. UpdateWindow(whichWindow)
  529. WindowPtr    whichWindow;
  530. {
  531. GrafPtr            oldPort;
  532. Rect            tempRect;
  533. LongRect        tempLongRect;
  534. RgnHandle        updateRgn;
  535.  
  536.     if (whichWindow != theWPtr)
  537.         return(FALSE);
  538.  
  539.     GetPort(&oldPort);
  540.     SetPort(whichWindow);
  541.     
  542.     PenNormal();
  543.     
  544.     BeginUpdate(whichWindow);
  545.     
  546.     tempRect = whichWindow->portRect;
  547.     EraseRect(&tempRect);
  548.     
  549.     if (whichWindow == theWPtr)
  550.     {
  551.         DrawGrowIcon(whichWindow);
  552.         DrawControls(whichWindow);
  553.         
  554.         updateRgn = ((WindowPeek) theWPtr)->updateRgn;
  555.         
  556.         tempLongRect.left = (**updateRgn).rgnBBox.left;
  557.         tempLongRect.top = (**updateRgn).rgnBBox.top;
  558.         tempLongRect.right = (**updateRgn).rgnBBox.right;
  559.         tempLongRect.bottom = (**updateRgn).rgnBBox.bottom;
  560.         
  561.         RectToLongRect(&tempRect,&tempLongRect);
  562.         TE32KUpdate(&tempLongRect,theTEH32K);
  563.     }
  564.     
  565.     EndUpdate(whichWindow);
  566.     
  567.     SetPort(oldPort);
  568.     
  569.     return(TRUE);
  570. }
  571.  
  572.  
  573.  
  574.  
  575.  
  576. void MyClicker()
  577. {
  578. int            controlMax,controlMin,controlVal,lineHeight;
  579. Rect        viewRect;
  580. Point        mousePoint;
  581. RgnHandle    saveClip;
  582. long        hDelta,vDelta;
  583.  
  584.     LongRectToRect(&((**theTEH32K).viewRect),&viewRect);
  585.     lineHeight = (**theTEH32K).lineHeight;
  586.  
  587.     hDelta = 0L;
  588.     vDelta = 0L;
  589.     
  590.     GetMouse(&mousePoint);
  591.     
  592.     if (!PtInRect(mousePoint,&viewRect))
  593.     {
  594.         controlMax = GetCtlMax(theVScroll);
  595.         controlMin = GetCtlMin(theVScroll);
  596.         controlVal = GetCtlValue(theVScroll);
  597.         
  598.         if (mousePoint.v>viewRect.bottom && controlVal<controlMax)
  599.         {
  600.             vDelta = -lineHeight;
  601.             SetCtlValue(theVScroll,controlVal+1);
  602.         }
  603.         
  604.         else if (mousePoint.v<viewRect.top && controlVal>controlMin)
  605.         {
  606.             vDelta = lineHeight;
  607.             SetCtlValue(theVScroll,controlVal-1);
  608.         }
  609.         
  610.         controlMax = GetCtlMax(theHScroll);
  611.         controlMin = GetCtlMin(theHScroll);
  612.         controlVal = GetCtlValue(theHScroll);
  613.         
  614.         if (mousePoint.h>viewRect.right && controlVal<controlMax)
  615.         {
  616.             hDelta = -lineHeight;
  617.             SetCtlValue(theHScroll,controlVal+1);
  618.         }
  619.         
  620.         else if (mousePoint.h<viewRect.left && controlVal>controlMin)
  621.         {
  622.             hDelta = lineHeight;
  623.             SetCtlValue(theHScroll,controlVal-1);
  624.         }
  625.     }
  626.     
  627.     if (hDelta || vDelta)
  628.     {
  629.         saveClip = NewRgn();
  630.         GetClip(saveClip);
  631.         ClipRect(&(theWPtr->portRect));
  632.         
  633.         TE32KScroll(hDelta,vDelta,theTEH32K);
  634.         
  635.         SetClip(saveClip);
  636.         DisposeRgn(saveClip);
  637.     }
  638. }
  639.  
  640.  
  641.  
  642.  
  643. void MyClickLoop()
  644. {
  645.     asm
  646.     {
  647.         movem.l        d1-d7/a0-a6,-(sp)
  648.         jsr            MyClicker
  649.         movem.l        (sp)+,d1-d7/a0-a6
  650.         moveq.l        #1,d0
  651.         rts
  652.     }
  653. }
  654.  
  655.  
  656.  
  657.  
  658. DoShowWindow()
  659. {
  660. Rect            tempRect;
  661. FontInfo        theFontInfo;
  662. LongRect        tempLongRect;
  663.  
  664.     if (theWPtr)
  665.         SelectWindow(theWPtr);
  666.         
  667.     else
  668.     {
  669.         SetRect(&tempRect,20,40,500,320);
  670.         
  671.         theWPtr = NewWindow (0L,&tempRect,"\pUntitled",TRUE,zoomDocProc,(WindowPtr) -1L,TRUE,0L);
  672.         if (StripAddress(theWPtr)==0L)
  673.         {
  674.             ErrorAlert("Insufficient memory to open window");
  675.             return;
  676.         }
  677.         
  678.         SetPort(theWPtr);
  679.         
  680.         TextFont(defaultFont);
  681.         TextSize(defaultFontSize);
  682.         TextFace(0);
  683.         TextMode(srcCopy);
  684.         
  685.         GetFontInfo(&theFontInfo);
  686.         
  687.         SetRect(&tempRect,(theWPtr)->portRect.right-15,(theWPtr)->portRect.top-1,(theWPtr)->portRect.right+1,(theWPtr)->portRect.bottom-14);
  688.         theVScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,0,scrollBarProc,0L);
  689.         
  690.         if (StripAddress(theVScroll)==0L)
  691.         {
  692.             DisposeWindow(theWPtr);
  693.             theWPtr = 0L;
  694.             theVScroll = 0L;
  695.             ErrorAlert("Insufficient memory to open edit record");
  696.             return;
  697.         }
  698.         
  699.         SetRect(&tempRect,(theWPtr)->portRect.left-1,(theWPtr)->portRect.bottom+1-16,(theWPtr)->portRect.right-14,(theWPtr)->portRect.bottom+1);
  700.         theHScroll = NewControl(theWPtr,&tempRect,"\p",TRUE,0,0,255,scrollBarProc,0L);
  701.         
  702.         if (StripAddress(theVScroll)==0L)
  703.         {
  704.             DisposeWindow(theWPtr);
  705.             DisposeControl(theVScroll);
  706.             theWPtr = 0L;
  707.             theVScroll = 0L;
  708.             theHScroll = 0L;
  709.             ErrorAlert("Insufficient memory to open edit record");
  710.             return;
  711.         }
  712.         
  713.         SetRect(&(tempRect),(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  714.         RectToLongRect(&tempRect,&tempLongRect);
  715.         theTEH32K = TE32KNew(&tempLongRect,&tempLongRect);
  716.     
  717.         if (StripAddress(theTEH32K)==0L)
  718.         {
  719.             DisposeControl(theVScroll);
  720.             DisposeControl(theHScroll);
  721.             DisposeWindow(theWPtr);
  722.             theWPtr = 0L;
  723.             theVScroll = 0L;
  724.             theHScroll = 0L;
  725.             ErrorAlert("Insufficient memory to open edit record");
  726.             return;
  727.         }
  728.         
  729.         (**theTEH32K).destRect.right -= 10;
  730.         
  731.         TE32KFromScrap();
  732.         
  733.         (*theTEH32K)->destRect.bottom = (*theTEH32K)->destRect.top + (((*theTEH32K)->destRect.bottom - (*theTEH32K)->destRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  734.         (*theTEH32K)->viewRect.bottom = (*theTEH32K)->viewRect.top + (((*theTEH32K)->viewRect.bottom - (*theTEH32K)->viewRect.top)/(*theTEH32K)->lineHeight)*(*theTEH32K)->lineHeight;
  735.         
  736.         (**theTEH32K).clikLoop = (ProcPtr) MyClickLoop;
  737.         
  738.         changed = FALSE;
  739.         
  740.         mySFReply.good = FALSE;
  741.     }
  742. }
  743.  
  744.  
  745.  
  746. DoKey(theChar)
  747. unsigned char    theChar;
  748. {
  749.     if (theWPtr && theWPtr == FrontWindow())
  750.     {
  751.         TE32KKey(theChar,theTEH32K);
  752.         
  753.         TE32KSelView(theTEH32K);
  754.         
  755.         changed = TRUE;
  756.         
  757.         AdjustScrollBar();
  758.         
  759.         return(TRUE);
  760.     }
  761.     
  762.     else
  763.         return(FALSE);
  764. }
  765.  
  766.  
  767. DoIdle()
  768. {
  769.     if (theWPtr && theWPtr == FrontWindow())
  770.     {
  771.         TE32KIdle(theTEH32K);
  772.         
  773.         return(TRUE);
  774.     }
  775.     
  776.     else
  777.         return(FALSE);
  778. }
  779.  
  780.  
  781.  
  782.  
  783.  
  784. MaintainCursor()
  785. {
  786. Point        pt;
  787. GrafPtr        oldPort;
  788. Rect        tempRect;
  789.  
  790.     if (theWPtr && FrontWindow() == theWPtr)
  791.     {
  792.         GetPort(&oldPort);
  793.         SetPort(theWPtr);
  794.         
  795.         SetRect(&tempRect,(theWPtr)->portRect.left+INDENT,(theWPtr)->portRect.top+INDENT,(theWPtr)->portRect.right-15-INDENT,(theWPtr)->portRect.bottom-16-INDENT);
  796.         
  797.         GetMouse(&pt);
  798.         
  799.         if (PtInRect(pt,&tempRect))
  800.             SetCursor(&editCursor);
  801.         
  802.         else
  803.             SetCursor(&arrow);
  804.         
  805.         return(TRUE);
  806.         
  807.         SetPort(oldPort);
  808.     }
  809.     
  810.     return(FALSE);
  811. }
  812.  
  813.  
  814.  
  815.  
  816. DoCut()
  817. {
  818.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  819.     {
  820.         SetCursor(&waitCursor);
  821.         TE32KCut(theTEH32K);
  822.         ZeroScrap();
  823.         TE32KToScrap();
  824.         AdjustScrollBar();
  825.         InitCursor();
  826.         
  827.         changed = TRUE;
  828.         
  829.         TE32KSelView(theTEH32K);
  830.         
  831.         return(TRUE);
  832.     }
  833.     
  834.     else
  835.         return(FALSE);
  836. }
  837.  
  838.  
  839.  
  840. DoCopy()
  841. {
  842.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  843.     {
  844.         SetCursor(&waitCursor);
  845.         TE32KCopy(theTEH32K);
  846.         ZeroScrap();
  847.         TE32KToScrap();
  848.         InitCursor();
  849.         
  850.         return(TRUE);
  851.     }
  852.     
  853.     else
  854.         return(FALSE);
  855. }
  856.  
  857.  
  858.  
  859.  
  860. DoPaste()
  861. {
  862.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  863.     {
  864.         SetCursor(&waitCursor);
  865.         TE32KFromScrap();
  866.         TE32KPaste(theTEH32K);
  867.         AdjustScrollBar();
  868.         InitCursor();
  869.         
  870.         changed = TRUE;
  871.         
  872.         TE32KSelView(theTEH32K);
  873.         
  874.         return(TRUE);
  875.     }
  876.     
  877.     else
  878.         return(FALSE);
  879. }
  880.  
  881.  
  882.  
  883.  
  884.  
  885. DoClear()
  886. {
  887.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  888.     {
  889.         SetCursor(&waitCursor);
  890.         TE32KDelete(theTEH32K);
  891.         AdjustScrollBar();
  892.         InitCursor();
  893.         
  894.         changed = TRUE;
  895.         
  896.         TE32KSelView(theTEH32K);
  897.         
  898.         return(TRUE);
  899.     }
  900.     
  901.     else
  902.         return(FALSE);
  903. }
  904.  
  905.  
  906.  
  907. DoSelectAll()
  908. {
  909.     if (theWPtr && FrontWindow() == theWPtr && theTEH32K)
  910.     {
  911.         SetCursor(&waitCursor);
  912.         TE32KSetSelect(0L,(**theTEH32K).teLength,theTEH32K);
  913.         AdjustScrollBar();
  914.         InitCursor();
  915.         
  916.         return(TRUE);
  917.     }
  918.     
  919.     else
  920.         return(FALSE);
  921. }